package com.mopoba.app;


import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;

import com.mrpoid.shequ2.R;


/**
 * 插件页
 * 
 * @author Yichou
 *
 */
public class PluginsGridFragment extends BaseGridFragment {
	String[] titles = new String[] {
		"更换背景",
		
	};
	
	Bitmap bmp_skin;
	

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		if(position == 0) {
			startActivityForResult(new Intent(getActivity(), ThemeActivity.class), 1001);
		}
	}
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(requestCode == 1001 && resultCode != 0) {
			((BaHomeActivity)getActivity()).setBackgroundColor(resultCode);
		}
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		bmp_skin = BitmapFactory.decodeResource(getResources(), R.drawable.ic_settings);
		
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public void onDestroy() {
		bmp_skin.recycle();
		bmp_skin = null;
		
		super.onDestroy();
	}

	@Override
	protected ListAdapter onCreateAdapter() {
		return new MyAdapter(getActivity());
	}
	
	private final class MyAdapter extends BaseGridAdapter {

		public MyAdapter(Context context) {
			super(context);
		}

		@Override
		public int getCount() {
			return 5;
		}

		@Override
		protected Bitmap getItemBg(int index) {
			if(index == 0)
				return bmp_skin;
			
			return null;
		}

		@Override
		protected String getItemTitle(int index) {
			if(index == 0)
				return titles[0];
			
			return null;
		}

		@Override
		protected Bitmap getItemImage(int index) {
			return null;
		}
	}
}
